package com.twu.biblioteca;

/**
 * Created by fish on 14-7-16.
 */
public class Book {
    private int id;
    private String author;
    private int yearPublished;
    private String title;

    public Book(int id, String author, int yearPublished, String title) {
        this.id = id;
        this.author = author;
        this.yearPublished = yearPublished;
        this.title = title;
    }

    public int getId() {
        return id;
    }

    public String getAuthor() {
        return author;
    }

    public int getYearPublished() {
        return yearPublished;
    }

    public String getTitle() {
        return title;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Book)) return false;

        Book book = (Book) o;

        if (id != book.id) return false;
        if (yearPublished != book.yearPublished) return false;
        if (!author.equals(book.author)) return false;
        if (!title.equals(book.title)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + author.hashCode();
        result = 31 * result + yearPublished;
        result = 31 * result + title.hashCode();
        return result;
    }

    public String displayString() {
        return String.format("%d\t%s\t%d\t%s",getId(),getAuthor(),getYearPublished(),getTitle());
    }
}
